package com.meihuak.cloud_ordering.controller;

import com.meihuak.cloud_ordering.bean.Comment;
import com.meihuak.cloud_ordering.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 韩迪
 * @date 2022/04/02 21:13
 **/

@Slf4j
@Controller
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    CommentService commentService;


    @RequestMapping("/addcomment")
    @ResponseBody
    public Map<String,Object> addComment(@RequestParam (value = "postid")Long postid,
                                         @RequestParam (value = "utype")String utype,
                                         @RequestParam (value = "userid")Integer userid,
                                         @RequestParam (value = "uname")String uname,
                                         @RequestParam (value = "content")String content){
        Map<String,Object> selMap = new HashMap<>();
        selMap.put("postid",postid);selMap.put("utype",utype);selMap.put("userid",userid);
        selMap.put("uname",uname);selMap.put("content",content);
        commentService.addCommentByPostId(selMap);
        Map<String,Object> ret = new HashMap<>();
        ret.put("msg","success");
        return ret;
    }

    @ResponseBody
    @RequestMapping("/getcomment")
    public List<Comment> getComment(@RequestParam (value = "utype")String utype,
                                         @RequestParam (value = "postid")Long postid,
                                         @RequestParam (value = "i")int i,
                                         @RequestParam (value = "m")int m){
        Map<String,Object> selMap = new HashMap<>();
        selMap.put("postid",postid);selMap.put("utype",utype);
        selMap.put("i",i);selMap.put("m",m);
        List<Comment> list = commentService.getCommentByPostId(selMap);
        return list;
    }






}
